package org.jwxa.jwxa4j.nodes;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * HTML Element对象
 * @author janjan, xujian_jason@163.com
 */
public class WXElement extends AbstractWXNode implements Serializable {
	private static final long serialVersionUID = 1L;

	// 标签名称
	private String tagName;
	// 元素属性
	private Map<String, String> attr;
	
	public WXElement(String tagName) {
		this(tagName, new HashMap<String, String>());
	}
	
	public WXElement(String tagName, Map<String, String> attr) {
		super("element");
		
		this.tagName = tagName;
		this.attr = attr;
	}
	
	public String getTagName() {
		return tagName;
	}

	public Map<String, String> getAttr() {
		return attr;
	}
	
	/**
	 * 设置属性
	 * @param attrKey 键key
	 * @param attrValue 值value
	 * @return
	 */
	public WXElement attr(String attrKey, String attrValue) {
		attr.put(attrKey, attrValue);
		return this;
	}
	
	public WXElement attrAll(Map<String, String> attrs) {
		if(attrs != null && !attrs.isEmpty()) {
			attr.putAll(attrs);
		}
		return this;
	}

}
